package com.qlk.vorder.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.vorder.domain.OrderNote;
import com.qlk.vorder.domain.query.OrderNoteQuery;
import com.qlk.vorder.dao.OrderNoteDao;
import com.qlk.vorder.manager.OrderNoteManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * OrderNoteManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-7-28 14:14:00
 * 
 */
@Component
public class OrderNoteManagerImpl extends BaseManager implements OrderNoteManager {

	@Autowired
	private OrderNoteDao orderNoteDao;

	/**
	 * {@inheritDoc}
	 */
	public boolean insert(final List<OrderNote> orderNoteList) {
		boolean resultFlag = false;
		if (null != orderNoteList && orderNoteList.size() > 0) {
			for (OrderNote orderNote : orderNoteList) {
				resultFlag = orderNoteDao.insert(orderNote);
				if (!resultFlag) {
					throw new RuntimeException("批量新增表信息异常");
				}
			}
		}

		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean insert(OrderNote orderNote) {
		return orderNoteDao.insert(orderNote);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean update(final OrderNote orderNote) {
		return orderNoteDao.update(orderNote);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<OrderNote> queryOrderNoteList(OrderNoteQuery queryBean) {
		return orderNoteDao.queryOrderNoteList(queryBean);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<OrderNote> queryOrderNoteListWithPage(OrderNoteQuery queryBean, PageUtil pageUtil) {
		if (null == queryBean) {
			queryBean = new OrderNoteQuery();
		}

		// 查询总数
		int totalItem = queryOrderNoteCount(queryBean);

		if (pageUtil == null) {
			pageUtil = new PageUtil();
		}
		pageUtil.setTotalRow(totalItem);
		pageUtil.init();

		if (totalItem > 0) {
			queryBean.setPageIndex(pageUtil.getCurPage());
			queryBean.setPageSize(pageUtil.getPageSize());
			// 调用Dao翻页方法
			return orderNoteDao.queryOrderNoteListWithPage(queryBean);
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public int queryOrderNoteCount(OrderNoteQuery queryBean) {
		return orderNoteDao.queryOrderNoteCount(queryBean);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean delete(OrderNote orderNote) {
		return orderNoteDao.delete(orderNote);
	}

	/**
	 * {@inheritDoc}
	 */
	public OrderNote getOrderNoteById(Long id) {
		return orderNoteDao.getOrderNoteById(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean delete(final OrderNote[] orderNotes) {
		boolean resultFlag = false;
		if (null != orderNotes && orderNotes.length > 0) {
			for (int i = 0; i < orderNotes.length; i++) {
				resultFlag = delete(orderNotes[i]);
				if (!resultFlag) {
					throw new RuntimeException("批量删除表信息异常!");
				}
			}
		}

		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean exist(OrderNote orderNote) {
		return orderNoteDao.exist(orderNote);
	}
}
